﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DreametryMIS
{
    public partial class UserControl1 : UserControl
    {
        List<Button> taskButton = new List<Button>();
        List<Label> taskID = new List<Label>();
        List<Label> tasklevel = new List<Label>();
        List<Button> taskDown = new List<Button>();
        List<Label> taskname = new List<Label>();
        public int Count;

        public UserControl1()
        {
            InitializeComponent();
        }

        public void getAll()
        {
            List<Panel> pnl = new List<Panel>();
            tasklevel = new List<Label>();
            taskname = new List<Label>();
            taskButton = new List<Button>();
            taskDown = new List<Button>();
            List<PictureBox> image = new List<PictureBox>();
            taskID = new List<Label>();

            FlowPanel.Controls.Clear();

            using (SqlConnection connection = new SqlConnection(ClassFlow.global_con))
            {
                SqlCommand command = new SqlCommand(ClassFlow.global_count, connection);
                command.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = ClassFlow.global_id;
                try
                {
                    command.Connection.Open();
                    Count = Int32.Parse(command.ExecuteScalar().ToString());
                }
                catch
                {
                    Count = 0;
                }   
            }
            for (int i = 0; i < Count; i++)
            {
                Panel pan = new Panel();
                pan.Name = "panel" + i;
                pan.BackColor = Color.White;
                pan.Dock = DockStyle.Top;
                pan.Padding = new Padding(10, 0, 10, 10);
                pan.Height = 80;
                pnl.Add(pan);

                Label id = new Label()
                {
                    Name = "id" + i,
                    ForeColor = Color.Black,
                    AutoSize = true,
                    BackColor = Color.Silver,
                    TextAlign = ContentAlignment.MiddleLeft,
                    Padding = new Padding(10, 10, 10, 10),
                    Text = "id",
                    Visible = false
                }; taskID.Add(id);

                Label lbl = new Label()
                {
                    Name = "lbl" + i,
                    ForeColor = Color.Black,
                    //Dock = DockStyle.Left,
                    AutoSize = false,
                    Width = 0,
                    BackColor = Color.Silver,
                    TextAlign = ContentAlignment.MiddleLeft,
                    Padding = new Padding(10, 10, 10, 10),
                    Text = "Designing",
                }; tasklevel.Add(lbl);

                Label tskname = new Label()
                {
                    Name = "tskName" + i,
                    ForeColor = Color.FromArgb(31, 31, 31),
                    Font = new Font("Segoe UI", 11, FontStyle.Regular),
                    Dock = DockStyle.Left,
                    AutoSize = false,
                    Width = 200,
                    BackColor = Color.Gainsboro,
                    TextAlign = ContentAlignment.MiddleCenter,
                    Padding = new Padding(10, 10, 10, 10),
                    Text = "Task Name",
                    Cursor = Cursors.Hand
                }; taskname.Add(tskname);
                taskname[i].Click += TasknameClick;

                PictureBox picBox = new PictureBox()
                {
                    Name = "picBox" + i,
                    Dock = DockStyle.Fill,
                    AutoSize = false,
                    Image = DreametryMIS.Properties.Resources.full,
                    SizeMode = PictureBoxSizeMode.StretchImage,
                    BackColor = Color.FromArgb(240, 240, 240),
                    Padding = new Padding(10, 10, 10, 10),

                }; image.Add(picBox);

                Button btn = new Button()
                {
                    Name = "btn" + i,
                    ForeColor = Color.Black,
                    Dock = DockStyle.Right,
                    AutoSize = true,
                    Width = 80,
                    FlatStyle = FlatStyle.Flat,
                    BackColor = Color.Gainsboro,
                    Font = new Font("Segoe UI", 11, FontStyle.Regular),
                    TextAlign = ContentAlignment.MiddleCenter,
                    Padding = new Padding(0, 10, 0, 10),
                    Cursor = Cursors.Hand,
                    Text = "Up",
                };
                btn.FlatAppearance.BorderSize = 0;
                taskButton.Add(btn);
                taskButton[i].Click += Clicked;

                Button btn2 = new Button()
                {
                    Name = "btn" + i,
                    ForeColor = Color.Black,
                    Dock = DockStyle.Right,
                    AutoSize = true,
                    Width = 80,
                    FlatStyle = FlatStyle.Flat,
                    BackColor = Color.Gainsboro,
                    Font = new Font("Segoe UI", 11, FontStyle.Regular),
                    TextAlign = ContentAlignment.MiddleCenter,
                    Padding = new Padding(0, 10, 0, 10),
                    Cursor = Cursors.Hand,
                    Text = "Down",
                };
                btn2.FlatAppearance.BorderSize = 0;
                taskDown.Add(btn2);
                taskDown[i].Click += Clicked2;

                pan.Controls.Add(picBox);
                pan.Controls.Add(id);
                pan.Controls.Add(btn);
                pan.Controls.Add(btn2);
                pan.Controls.Add(lbl);
                pan.Controls.Add(tskname);
                FlowPanel.Controls.Add(pan);
            }
                using (SqlConnection connection = new SqlConnection(ClassFlow.global_con))
                using (SqlDataAdapter adapter = new SqlDataAdapter(ClassFlow.unique_SQL_String, connection))
                {
                    try
                    {
                        DataTable users = new DataTable();
                        adapter.Fill(users);
                        dataGridView1.DataSource = users;
                    }
                    catch
                    {

                    }
                }
            

            for (int i = 0; i < Count; i++)
                {
                    taskname[i].Text = dataGridView1.Rows[i].Cells["task_name"].Value.ToString();
                    tasklevel[i].Text = dataGridView1.Rows[i].Cells["flow_id"].Value.ToString();
                    taskID[i].Text = dataGridView1.Rows[i].Cells["task_id"].Value.ToString();

                    if (tasklevel[i].Text == "1")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f1;
                        taskDown[i].Visible = false;
                        taskButton[i].Width = 160;
                    }
                    else if (tasklevel[i].Text == "2")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f2;
                    }
                    else if (tasklevel[i].Text == "3")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f3;
                    }
                    else if (tasklevel[i].Text == "4")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f4;
                    }
                    else if (tasklevel[i].Text == "5")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f5;
                    }
                    else if (tasklevel[i].Text == "6")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f6;
                    }
                    else if (tasklevel[i].Text == "7")
                    {
                        image[i].Image = DreametryMIS.Properties.Resources.f7;
                        taskButton[i].Text = "Done";
                }
            }
            
        }
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            getAll();
        }
        String nickname;
        public void Clicked(object sender, EventArgs e)
        {
 
            if (MessageBox.Show("Are you sure you want to level up this task?", "Level up task", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Button button = sender as Button;
                int idx = taskButton.IndexOf(button);
                int x = Convert.ToInt32(tasklevel[idx].Text.ToString()) + 1;
               
                String commandText = "UPDATE TaskTable SET flow_id = " + x + " WHERE task_id = " + Convert.ToInt32(taskID[idx].Text.ToString());

                using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                {
                    SqlCommand com = new SqlCommand(commandText, con);
                    com.Connection.Open();
                    com.ExecuteNonQuery();
                }

                //start test code

                String taskinProgress = "SELECT Employee.taskInProgress FROM Employee INNER JOIN TaskTable ON Employee.emp_id = TaskTable.emp_id WHERE task_id = @Name";

                using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                {
                    SqlCommand command = new SqlCommand(taskinProgress, con);
                    command.Parameters.Add("@Name", SqlDbType.Int, 5).Value = Convert.ToInt32(taskID[idx].Text.ToString());
                    try
                    {
                        command.Connection.Open();
                        nickname = command.ExecuteScalar().ToString();
                    }
                    catch
                    {
                        nickname = "";

                    }
                    finally
                    {
                        command.Connection.Close();
                    }



                }
                //end test code

                if ((tasklevel[idx].Text == "1"))
                {
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Designer: " + ClassFlow.global_fullname + "Check ArtWork" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Designer: " + ClassFlow.global_fullname + "Check ArtWork", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Verify Logs\logs.txt");
                }
                else if ((tasklevel[idx].Text == "2"))
                {
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Verifier: " + ClassFlow.global_fullname + "ArtWork Verified" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Verifier: " + ClassFlow.global_fullname + "ArtWork Verified", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                }
                else if ((tasklevel[idx].Text == "3"))
                {
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Designer: " + ClassFlow.global_fullname + "Submitted for Batch Edit" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Designer: " + ClassFlow.global_fullname + "Submitted for Batch Edit", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Uploader Logs\logs.txt");
                }
                else if ((tasklevel[idx].Text == "4"))
                {
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Uploader: " + ClassFlow.global_fullname + "CSV send For Verification" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Uploader: " + ClassFlow.global_fullname + "CSV send For Verification", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Verify Logs\logs.txt");
                }
                else if ((tasklevel[idx].Text == "5"))
                {
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Verifier: " + ClassFlow.global_fullname + "CSV Verified" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Verifier: " + ClassFlow.global_fullname + "CSV Verified", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Uploader Logs\logs.txt");
                }
                else if ((tasklevel[idx].Text == "6"))
                {
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Uploader: " + ClassFlow.global_fullname + "Uploaded" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Uploader: " + ClassFlow.global_fullname + "Uploaded", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                }
                else if ((tasklevel[idx].Text == "7"))
                {
                    
                    String com = promptDone.ShowDialog("Output Description", "Write Description", taskname[idx].Text, nickname);
                    String finalcom = com.Replace(Environment.NewLine, "<br>");
                    String updatequery = "UPDATE TaskTable SET output_description = '" + finalcom + "' WHERE task_id = " + Convert.ToInt32(taskID[idx].Text.ToString());

                    using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                    {
                        SqlCommand com3 = new SqlCommand(updatequery, con);
                        com3.Connection.Open();
                        com3.ExecuteNonQuery();
                    }
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Designer: " + ClassFlow.global_fullname + "Task Completed" + Environment.NewLine + com + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Designer: " + ClassFlow.global_fullname + "Task Completed" + Environment.NewLine + com, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                }
                getAll();
            }
        }

        public void Clicked2(object sender, EventArgs e)
        {
            
            if (MessageBox.Show("Are you sure you want to level down this task?", "Level down task", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Button button = sender as Button;
                int idx = taskDown.IndexOf(button);
                int x = Convert.ToInt32(tasklevel[idx].Text.ToString()) - 1;
                
                String commandText = "UPDATE TaskTable SET flow_id = " + x + " WHERE task_id = " + Convert.ToInt32(taskID[idx].Text.ToString());

             //  using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
             //  {
             //      SqlCommand com = new SqlCommand(commandText, con);
             //      com.Connection.Open();
             //      com.ExecuteNonQuery();
             //  }

                //start test code

                String taskinProgress = "SELECT Employee.taskInProgress FROM Employee INNER JOIN TaskTable ON Employee.emp_id = TaskTable.emp_id WHERE task_id = @Name";

              using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
              {
                  SqlCommand command = new SqlCommand(taskinProgress, con);
                  command.Parameters.Add("@Name", SqlDbType.Int, 5).Value = Convert.ToInt32(taskID[idx].Text.ToString());
                  try
                  {
                      command.Connection.Open();
                      nickname = command.ExecuteScalar().ToString();
                  }
                  catch
                  {
                      nickname = "";
             
                  }
                  finally
                  {
                      command.Connection.Close();
                  }



                }
                //end test code

                if ((tasklevel[idx].Text == "2"))
                {
                    String com = promptDone.ShowDialog("Please add comment", "Write Comments", taskname[idx].Text, nickname);
                    if (com != "")
                    {
                        using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                        {
                            SqlCommand com2 = new SqlCommand(commandText, con);
                            com2.Connection.Open();
                            com2.ExecuteNonQuery();
                        }
                        MessageBox.Show(ClassFlow.global_count);
                        writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Verifier: " + ClassFlow.global_fullname + "ArtWork Correction", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                        writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Verifier: " + ClassFlow.global_fullname + "ArtWork Correction", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                        writeFile.Main("Comment: " + com + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    }
                    else
                    {
                        MessageBox.Show("Please add comment");
                    }
                }
                else if ((tasklevel[idx].Text == "3"))
                {
                    using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                    {
                        SqlCommand com2 = new SqlCommand(commandText, con);
                        com2.Connection.Open();
                        com2.ExecuteNonQuery();
                    }
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Verifying Design", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Verifying Design" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                }
                else if ((tasklevel[idx].Text == "4"))
                {
                    String com = promptDone.ShowDialog("Please add comment", "Write Comments", taskname[idx].Text, nickname);
                    if (com != "")
                    {
                        using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                        {
                            SqlCommand com2 = new SqlCommand(commandText, con);
                            com2.Connection.Open();
                            com2.ExecuteNonQuery();
                        }
                        writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Uploader: " + ClassFlow.global_fullname + "Design Correction", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                        writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Uploader: " + ClassFlow.global_fullname + "Design Correction", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                        writeFile.Main("Comment: " + com + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                    }
                    else
                    {
                        MessageBox.Show("Please add comment");
                    }
                }

                else if ((tasklevel[idx].Text == "5"))
                {
                    using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                    {
                        SqlCommand com2 = new SqlCommand(commandText, con);
                        com2.Connection.Open();
                        com2.ExecuteNonQuery();
                    }
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Batch Editing", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Batch Editing" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                }
                else if ((tasklevel[idx].Text == "6"))
                {
                    using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                    {
                        SqlCommand com2 = new SqlCommand(commandText, con);
                        com2.Connection.Open();
                        com2.ExecuteNonQuery();
                    }
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Verifying CSV", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Verifying CSV" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                }
                else if ((tasklevel[idx].Text == "7"))
                {
                    using (SqlConnection con = new SqlConnection(ClassFlow.global_con))
                    {
                        SqlCommand com2 = new SqlCommand(commandText, con);
                        com2.Connection.Open();
                        com2.ExecuteNonQuery();
                    }
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Uploading", @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\Deo\C#\Backup Files\Designers Logs\logs.txt");
                    writeFile.Main("Date: " + DateTime.Now + Environment.NewLine + "Task name: " + taskname[idx].Text + Environment.NewLine + "Updated by: " + ClassFlow.global_fullname + "Leveled down to Uploading" + Environment.NewLine + Environment.NewLine + ClassFlow.line + Environment.NewLine, @"\\server-pc\Dropbox\_____Codiga\_____AI and PSD Files\____TASKS IN PROGRESS\" + nickname + @"\logs\" + taskname[idx].Text + @".txt");
                }
               // MessageBox.Show(ClassFlow.global_count.ToString());
               getAll();
            }
        }
        public void TasknameClick(object sender, EventArgs e)
        {
            Label label = sender as Label;
            int idx = taskname.IndexOf(label);

            String desc = taskID[idx].Text = dataGridView1.Rows[idx].Cells["task_description"].Value.ToString();
            //String date = taskID[idx].Text = dataGridView1.Rows[idx].Cells["date"].Value.ToString();

            try
            {
                System.Diagnostics.Process.Start(desc.ToString());
                getAll();
            }
            catch
            {
                MessageBox.Show("Invalid link address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                getAll();
            }
            /*
            if (MessageBox.Show("This task was created on "+date.ToString()+ Environment.NewLine+"Do you want to go to the link?" + Environment.NewLine+desc.ToString(), "Details", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
            {
                try
                {
                    System.Diagnostics.Process.Start(desc.ToString());
                    getall();
                }
                catch
                {
                    MessageBox.Show("Invalid link address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    getall();
                }

            }*/
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {
            getAll();
        }
    }
}
